const { contextBridge, ipcRenderer } = require('electron')

const sendUrl = async (url) => {
    return await ipcRenderer.invoke('on-url-event', url)
}

const alert = (msg) => ipcRenderer.invoke('on-alert-event', msg)


const openBrowserWindow = (url) => ipcRenderer.invoke('on-openWindow-event', url)

const watchDownloadEvent = () => {
    ipcRenderer.send('on-watch-download-event')
}

const onDownloadEvent = (callback) => {
    ipcRenderer.on('on-download-event', (e, file) => {
        callback(file)
    })
}

const readImg = async (file) => {
    // const data = await fs.readFile(path)
}

contextBridge.exposeInMainWorld('Bookmark', {
    sendUrl,
    alert,
    readImg,
    openBrowserWindow,
    watchDownloadEvent,
    onDownloadEvent
})
